@echo off

REM 设置发布目录
REM !!! 注意: 如果需要发布到其它目录，请按需要修改 !!!
set DIST=..\..\dist\windows

REM 设置 Visual C++ 编译器命令行环境
REM !!! 注意: 如果目录不正确，请按实际情况修改 !!!
if "%VCToolsVersion%"=="" call "C:\dev-tools\vs2022\VC\Auxiliary\Build\vcvarsall.bat" x64 10.0.22621.0
REM if "%VCToolsVersion%"=="" call "C:\dev-tools\vs2019\VC\Auxiliary\Build\vcvarsall.bat" %ARCH% 10.0.19041.0
REM if "%VCINSTALLDIR%"=="" call "C:\dev-tools\vs2015\VC\vcvarsall.bat" %ARCH% 8.1
REM call "C:\dev-tools\vc2010\setupenv.bat"
REM call "C:\dev-tools\vc2005\setupenv.bat"

pushd %~dp0

REM 编译生成资源 dll
mc log4winevent.mc
rc log4winevent.rc
link /DLL /NOENTRY /MACHINE:X64 log4winevent.res

REM 拷贝生成的资源 dll 到发布目录
xcopy /Y /F log4winevent.dll %DIST%\

pushd %DIST%
REM 注册事件来源与资源 dll 关联
REM !!! 注意: 如果需要注册更多事件来源，请按需要添加或修改下面的事件列表 !!!
for %%s in (Log4WinEvent RM-AppLog ZyTest) do (
	reg add "HKLM\SYSTEM\CurrentControlSet\Services\EventLog\Application\%%s" /f /v CategoryCount        /t REG_DWORD /d 1
	reg add "HKLM\SYSTEM\CurrentControlSet\Services\EventLog\Application\%%s" /f /v TypesSupported       /t REG_DWORD /d 2
	reg add "HKLM\SYSTEM\CurrentControlSet\Services\EventLog\Application\%%s" /f /v CategoryMessageFile  /t REG_SZ /d "%CD%\log4winevent.dll"
	reg add "HKLM\SYSTEM\CurrentControlSet\Services\EventLog\Application\%%s" /f /v EventMessageFile     /t REG_SZ /d "%CD%\log4winevent.dll"
	reg add "HKLM\SYSTEM\CurrentControlSet\Services\EventLog\Application\%%s" /f /v ParameterMessageFile /t REG_SZ /d "%CD%\log4winevent.dll"
)
popd

REM 删除不再需要的文件
del log4winevent.rc log4winevent.res MSG*.bin log4winevent.dll

popd
